﻿// ***********************************************************************
// Assembly         : INNOVACALL.Framework.Common
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="EnumMETAExtension.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using INNOVACALL.Framework.Common.HTMLHelpers;

namespace INNOVACALL.Framework.Common.Extensions
{
    /// <summary>
    /// Class EnumMETAExtension
    /// </summary>
    public static class EnumMETAExtensions
    {
        /// <summary>
        /// The _enum type
        /// </summary>
        private static Type _enumType;
        /// <summary>
        /// The _ HTML values
        /// </summary>
        private static Hashtable _HTMLValues = new Hashtable();

        /// <summary>
        /// HTMLs the properties.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>HtmlMetaOptionLocalizedAttribute.</returns>
        public static HtmlMetaOptionLocalizedAttribute HTMLProperties(this Enum value)
        {
            HtmlMetaOptionLocalizedAttribute output = null;
            Type type = value.GetType();

            if (_HTMLValues.ContainsKey(value))
                output = (_HTMLValues[value] as HtmlMetaOptionLocalizedAttribute);
            else
            {
                //Look for our 'StringValueAttribute' in the field's custom attributes
                FieldInfo fi = type.GetField(value.ToString());
                HtmlMetaOptionLocalizedAttribute[] attrs = fi.GetCustomAttributes(typeof(HtmlMetaOptionLocalizedAttribute), false) as HtmlMetaOptionLocalizedAttribute[];
                if (attrs.Length > 0)
                {
                    //ToDo LJO imrove
                    try {
                        _HTMLValues.Add(value, attrs[0]);
                    } catch(Exception ex){};
                    output = attrs[0];
                }
            }
            return output;
        }
    }
}
